<?php

require_once('base.php');
require_once $CFG->dirroot . 'mod/folio/model/decoration.php';

class folio_DecorationView extends folio_BaseView {

    private $decoration;

    function __construct( folio_decoration $decoration) {
        $this->decoration = $decoration;
		
		// Return empty if the user doesn't have permission to edit.
		if( !$decoration->Permission() )
			return;

        $this->html = <<< END
        <div id="{$this->decoration->handle()}_text" class="folio_decoration">{$this->decoration->text}</div>
END;
        $this->metatags = array('mod/friend/css.css');
    }
}

class folio_DecorationEditor extends folio_BaseView {

    private $decoration;

    function __construct( folio_decoration $decoration) {
        $this->decoration = $decoration;

		// Return empty if the user doesn't have permission to edit.
		if( !$decoration->Permission() )
			return;
			
			
        $this->metatags = array('mod/folio/js/edit.js' );

        // Set html
        global $CFG;
        $www = $CFG->wwwroot;
        $oHandle = __gettext('Click and drag this to move up or down');
        $oDelete = __gettext('Click to delete');

        $handle_text = "<img id='folio_clip_decoration{$this->decoration->decoration_ident}".
            "' src='{$www}mod/folio/image/RichEditor_Move.png' alt='" . $oHandle . "' />";
        $delete_text = "<a href=\"javascript:folio_RichEditor_Delete( " .
            "{$this->decoration->decoration_ident}, 'decoration');\" >" .
            "<img id='folio_delete_decoration{$this->decoration->decoration_ident}'" .
            "src='{$www}mod/folio/image/RichEditor_Delete.png' alt='" . $oDelete .
            "' class='folio_edit' /></a>";

        $text = ( strlen( $this->decoration->text ) == 0 ? 'Click to add text' : $this->decoration->text );

        if( 'label' == $this->decoration->type ||
			'private' == $this->decoration->type ) {
            // Plain label
            $html = <<< END
                <li id="{$this->decoration->handle()}">
                    <br/>
                    <span id="{$this->decoration->handle()}_handle" class="handle">{$handle_text}</span>
                    {$delete_text}
                    <div id="{$this->decoration->handle()}_text" class='folio_page_editable'>{$text}</div>
                </li>
END;

            $this->js = <<< END
                folio_ajax_makeRichEditable('{$this->decoration->decoration_ident}','decoration', 'text', '{$this->decoration->handle()}_text');
END;

        } elseif ( $this->decoration->type == 'html' ) {
            $html = <<< END
                <br/>
                <li id="{$this->decoration->handle()}">
                    <span id="{$this->decoration->handle()}_handle" class="handle">{$handle_text}</span>
                    {$delete_text}
                    <div id="{$this->decoration->handle()}_text">{$text}</div>
                </li>
END;
        } else {
            trigger_error('Invalid type "' . $this->decoration->type . '" passed to folio_DecorationEditor()', E_USER_ERROR);
        }

        $this->html = $html;

        // Load tooltips
        $this->Load(new folio_Tooltip('folio_clip_decoration' .
                                        $this->decoration->decoration_ident, $oHandle));
        $this->Load(new folio_Tooltip("folio_delete_decoration" .
                                      $this->decoration->decoration_ident, $oDelete));
    }

}
?>
